﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class SysShopSettlement
    {
        private readonly Chain.IDAL.SysShopSettlement dal = new Chain.IDAL.SysShopSettlement();

        public int Add(Chain.Model.SysShopSettlement model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.SysShopSettlement> DataTableToList(DataTable dt)
        {
            List<Chain.Model.SysShopSettlement> list = new List<Chain.Model.SysShopSettlement>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.SysShopSettlement item = new Chain.Model.SysShopSettlement();
                    if ((dt.Rows[i]["ID"] != null) && (dt.Rows[i]["ID"].ToString() != ""))
                    {
                        item.ID = int.Parse(dt.Rows[i]["ID"].ToString());
                    }
                    if ((dt.Rows[i]["StartTime"] != null) && (dt.Rows[i]["StartTime"].ToString() != ""))
                    {
                        item.StartTime = DateTime.Parse(dt.Rows[i]["StartTime"].ToString());
                    }
                    if ((dt.Rows[i]["EndTime"] != null) && (dt.Rows[i]["EndTime"].ToString() != ""))
                    {
                        item.EndTime = DateTime.Parse(dt.Rows[i]["EndTime"].ToString());
                    }
                    if ((dt.Rows[i]["RechargeMoney"] != null) && (dt.Rows[i]["RechargeMoney"].ToString() != ""))
                    {
                        item.RechargeMoney = decimal.Parse(dt.Rows[i]["RechargeMoney"].ToString());
                    }
                    if ((dt.Rows[i]["DrawMoney"] != null) && (dt.Rows[i]["DrawMoney"].ToString() != ""))
                    {
                        item.DrawMoney = decimal.Parse(dt.Rows[i]["DrawMoney"].ToString());
                    }
                    if ((dt.Rows[i]["PayCard"] != null) && (dt.Rows[i]["PayCard"].ToString() != ""))
                    {
                        item.PayCard = decimal.Parse(dt.Rows[i]["PayCard"].ToString());
                    }
                    if ((dt.Rows[i]["IsFinish"] != null) && (dt.Rows[i]["IsFinish"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["IsFinish"].ToString() == "1") || (dt.Rows[i]["IsFinish"].ToString().ToLower() == "true"))
                        {
                            item.IsFinish = true;
                        }
                        else
                        {
                            item.IsFinish = false;
                        }
                    }
                    if ((dt.Rows[i]["FinishTime"] != null) && (dt.Rows[i]["FinishTime"].ToString() != ""))
                    {
                        item.FinishTime = DateTime.Parse(dt.Rows[i]["FinishTime"].ToString());
                    }
                    if ((dt.Rows[i]["Remark"] != null) && (dt.Rows[i]["Remark"].ToString() != ""))
                    {
                        item.Remark = dt.Rows[i]["Remark"].ToString();
                    }
                    if ((dt.Rows[i]["OutShopID"] != null) && (dt.Rows[i]["OutShopID"].ToString() != ""))
                    {
                        item.OutShopID = int.Parse(dt.Rows[i]["OutShopID"].ToString());
                    }
                    if ((dt.Rows[i]["UserID"] != null) && (dt.Rows[i]["UserID"].ToString() != ""))
                    {
                        item.UserID = int.Parse(dt.Rows[i]["UserID"].ToString());
                    }
                    if ((dt.Rows[i]["AllExpenseMoney"] != null) && (dt.Rows[i]["AllExpenseMoney"].ToString() != ""))
                    {
                        item.AllExpenseMoney = Convert.ToDecimal(dt.Rows[i]["AllExpenseMoney"].ToString());
                    }
                    if ((dt.Rows[i]["ProportionMoney"] != null) && (dt.Rows[i]["ProportionMoney"].ToString() != ""))
                    {
                        item.ProportionMoney = Convert.ToDecimal(dt.Rows[i]["ProportionMoney"].ToString());
                    }
                    if ((dt.Rows[i]["Proportion"] != null) && (dt.Rows[i]["Proportion"].ToString() != ""))
                    {
                        item.Proportion = Convert.ToDecimal(dt.Rows[i]["Proportion"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int ID)
        {
            return this.dal.Delete(ID);
        }

        public bool DeleteList(string IDlist)
        {
            return this.dal.DeleteList(IDlist);
        }

        public bool Exists(int ID)
        {
            return this.dal.Exists(ID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, string join, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, join, out resCount, strWhere);
        }

        public Chain.Model.SysShopSettlement GetModel(int ID)
        {
            return this.dal.GetModel(ID);
        }

        public List<Chain.Model.SysShopSettlement> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.SysShopSettlement model)
        {
            return this.dal.Update(model);
        }

        public void UpDateSettlement()
        {
            this.dal.UpDateSettlement();
        }
    }
}

